package com.kfm.jdbc.day0327;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class Demo05 {

    public static void main(String[] args) {
        Class<Student> studentClass = Student.class;

        // 获取到所有 public 修饰的方法包含继承到的 public 方法
        Method[] methods = studentClass.getMethods();
        // 类中所有声明的方法
        Method[] declaredMethods = studentClass.getDeclaredMethods();

//        System.out.println(Arrays.toString(methods));
//        System.out.println(Arrays.toString(declaredMethods));

        try {
            // 获取方法
            Method say = studentClass.getMethod("say");
            Method show = studentClass.getMethod("show", String.class);

//            System.out.println(say);
//            System.out.println(show);

            // 调用方法 obj.say();
            Student student = studentClass.newInstance();
////            say.invoke(student);
//            show.invoke(student, "admin");

            Method staticMethod = studentClass.getMethod("staticMethod");
            // static 方法的调用
            staticMethod.invoke(null);

        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
